<template>
    <div class="app-container">
        <!-- 查询条件开始 -->
        <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="98px">
            <el-form-item label="患者姓名" prop="patientName">
                <el-input
                        v-model="queryParams.patientName"
                        placeholder="请输入患者姓名"
                        clearable
                        size="small"
                        style="width:240px"
                />
            </el-form-item>
            <el-form-item label="挂号单号" prop="regId">
                <el-input
                        v-model="queryParams.regId"
                        placeholder="请输入挂号单号"
                        clearable
                        size="small"
                        style="width:240px"
                />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="queryAll">搜索</el-button>
                <el-button type="primary" icon="el-icon-refresh" size="mini" @click="findList">重置</el-button>
            </el-form-item>
        </el-form>
        <!-- 数据表格开始 -->
        <el-table  border :data="orderBackfeeTableList">
            <el-table-column label="退费订单号" align="center" width="210" prop="backId" />
            <el-table-column label="挂号单号" align="center" width="200" prop="regId" />
            <el-table-column label="患者姓名" align="center" prop="patientName" />
            <el-table-column label="总金额" align="center" prop="backAmount" />
            <el-table-column label="退费类型" align="center" prop="backType"  :formatter="backTypeFormat" />
            <el-table-column label="订单状态" prop="backStatus" align="center" :formatter="backStatusFormat" />
            <el-table-column label="创建时间" align="center" prop="createTime" />
            <el-table-column label="操作" width="300px" align="center">
                <template slot-scope="scope">
                    <el-button type="text" icon="el-icon-view" size="mini" @click="findBack(scope.row)">查看详情</el-button>
                </template>
            </el-table-column>
        </el-table>

        <!-- 分页控件开始 -->
        <el-pagination
                v-show="total>0"
                :current-page="current"
                :page-sizes="[6, 10, 20, 30]"
                :page-size="size"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
        />
        <!-- 分页控件结束 -->
    <!-- 查看详情的弹出层开始 -->
    <el-dialog
            :title="title"
            :visible.sync="open"
            width="1000px"
            center
            append-to-body
    >
        <el-table
                v-loading="itemTableloading"
                border
                :data="orderBackfeeItemList"
        >
            <el-table-column label="详情ID" align="center" width="210" prop="itemId" />
            <el-table-column label="处方ID" align="center" width="200" prop="coId" />
            <el-table-column label="名称" align="center" prop="itemName" />
            <el-table-column label="价格" align="center" prop="itemPrice" />
            <el-table-column label="数量" align="center" prop="itemNum" />
            <el-table-column label="小计" prop="itemAmount" align="center" />
            <el-table-column label="类型" align="center" prop="itemType" >
                <template slot-scope="scope">
                    {{ scope.row.itemType==='0'?'药品':'检查' }}
                </template>
            </el-table-column>
            <el-table-column label="状态" align="center" prop="status" :formatter="statusFormatter" />
        </el-table>
        <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">关 闭</el-button>
      </span>
    </el-dialog>
    </div>
    <!-- 查看详情的弹出层结束 -->
</template>

<script>
    export default {
        name: "backfeelist",
        data(){
            return{
                queryParams:{},
                //查询全部并分页
                orderBackfeeTableList:[],

                // 字典表
                backTypeOptions:[],
                statusOptions:[],
                itemTypeOptions:[],

                //查看详情的参数
                title:'',
                open:false,
                orderBackfeeItemList:[],

                itemTableloading:false,

                //分页参数
                current:1,
                size:6,
                total:0

            }
        },
        methods:{
            queryAll(){
                this.current=1;
                this.findAll();
            },
            //查询全部分页
            findAll(){
                this.$axios.post('/charge/api/findAll/'+this.current+'/'+this.size,this.queryParams).then(result=>{
                    this.orderBackfeeTableList=result.data.data.records;
                    this.total=result.data.data.total;
                })
            },
            //查看详情
            findBack(row){
                this.title='查看【'+row.patientName+'】退费订单的详情';
                this.open=true;
                this.itemTableloading=true;
                this.$axios.get('/charge/api/item/findUserByStatus/'+row.backId).then(result=>{
                    this.orderBackfeeItemList=result.data.data;
                    this.itemTableloading=false;
                })
            },
            initBackType(){
                this.$axios.get("/charge/api/item/findAllByType/his_pay_type_status").then(result=>{
                    this.backTypeOptions=result.data.data;
                })
            },
            initBackStatus(){
                this.$axios.get("/charge/api/item/findAllByType/his_backfee_status").then(result=>{
                    this.statusOptions=result.data.data;
                })
            },
            initItemType(){
                this.$axios.get("/charge/api/item/findAllByType/his_order_details_status").then(result=>{
                    this.itemTypeOptions=result.data.data;
                })
            },


            statusFormatter(row){
                let s = row.status;
                return this.formatDict(this.itemTypeOptions,s);
            },
            backStatusFormat(row){
                let b = row.backStatus;
                return this.formatDict(this.statusOptions,b);
            },
            backTypeFormat(row){
                let t = row.backType;
                return this.formatDict(this.backTypeOptions,t);
            },


            cancel(){
              this.open=false;
            },

            findList(){
                this.queryParams = {};
                this.findAll();
            },


            handleSizeChange(row){
                this.size = row;
                this.findAll();
            },
            handleCurrentChange(row){
                this.current=row;
                this.findAll();
            }
        },
        created() {
            //查询全部
            this.findAll();

            this.initBackType();
            this.initBackStatus();
            this.initItemType();
        }

    }
</script>

<style scoped>

</style>
